// pages/store/store_xq.js
Page({
  data: {
    id:'',
    banner:[],shopinfo:{},goods:[],longitudeshop:'',latitudeshop:'',goods_id:'',
    latitude: 40.048828,
    longitude: 116.280412,
    scale:16,
    markers: [{
        id:1,
        markerId: 1,
        name:2,
        latitude: 40.048828,
        longitude: 116.280412,
        title: 'markerId: 1',
        width:30,
        height:30,
        zIndex: 100,
        iconPath: '../../images/1.jpg',  
        callout: {
            display: 'BYCLICK',
            content: '我的位置',
            color: '#000',
            fontSize: '16',
            borderRadius: 50,
            bgColor: '#5B9FFF',
            padding: 2,
            textAlign: 'center'
        }
    }]
  },

  
  onLoad: function (options) {
    this.getlocation()
    
    var that = this
    console.log(options);
    
    that.setData({
      id:options.id,
    }) 
    console.log(that.data.id);
    
    that.getgoodslist()
    wx.request({
      url: 'https://zujieba.com/api/store/index.html', //仅为示例，并非真实的接口地址
      data: {
        pid:this.data.id
      },
      success: function(res) {
        console.log(res);
        
       
        
       if(res.data.success == 2){
          wx.showToast({
            title: res.data.tips,
            // icon: ' ', 
            image:'../../images/error.png',
            duration: 1500,    
            mask:true    //是否有透明蒙层，默认为false 
                         //如果有透明蒙层，弹窗的期间不能点击文档内容 
          })
          setTimeout(function () {
            wx.navigateBack({
              delta: 1,  // 返回上一级页面。
            })
          }, 1500);
        }else{
          that.setData({
            banner:res.data.data.banner,
            shopinfo:res.data.data,
            longitudeshop:res.data.data.lng,
            latitudeshop:res.data.data.lat
          })
          
          
        }
        }
    })

  },
  
  getgoodslist(){
    
    
    
    wx.request({
      url: 'https://zujieba.com/api/store/goods.html',
      data: {
        pid:this.data.id
      },
      method:"POST",
      success:(res)=>{
           const goods=res.data.data
           this.setData({
             goods,
            goods_id:res.data.data[0].id
           })
           console.log(res);
           

           
      }

    })
  }
  ,
  //跳转打印
  printclick(){
    wx.navigateTo({
      url: '/pages/store/print/print?id='+this.data.goods_id,
    })

  },
  getlocation(){
    wx.getLocation({
      altitude: 'false',
      success:(res)=>{
        let longitude="markers[0].longitude"
           let latitude="markers[0].latitude"
           this.setData({
           latitude:res.latitude,
           longitude:res.longitude,
           [longitude]:res.longitude,
           [latitude]:res.latitude

           })
       
      }
    })
  }
,
mapclick(){
  wx.openLocation({
    
    latitude: parseInt(this.data.latitudeshop),
    longitude:parseInt(this.data.longitudeshop),
  })
  
}
  


})